package cn.dnui_jzy913.dnuifood_16110100913.Activity;

import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageButton;

import java.util.List;

import cn.dnui_jzy913.dnuifood_16110100913.Adapter.PingjiaAdapter;
import cn.dnui_jzy913.dnuifood_16110100913.R;
import cn.dnui_jzy913.dnuifood_16110100913.bean.CommentsBean;
import cn.dnui_jzy913.dnuifood_16110100913.listener.RetrofitListener;
import cn.dnui_jzy913.dnuifood_16110100913.model.UserModel;

public class MypingjiaActivity extends BaseActivity implements RetrofitListener<List<CommentsBean>> {
    private RecyclerView recyclerView;
    private ImageButton fanhui;
    private UserModel userModel;
    private PingjiaAdapter adapter;
    @Override
    protected int initlayout() {
        return R.layout.activity_mypingjia;
    }

    @Override
    void initViews() {
        fanhui = findViewById(R.id.img_btn_pingjia);
        recyclerView = findViewById(R.id.rv_my_pingjia);
    }

    @Override
    void initEvents() {
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(
                this,
                LinearLayoutManager.VERTICAL,
                false
        );//布局效果---垂直布局
        recyclerView.setLayoutManager(linearLayoutManager);//设置效果
        recyclerView.setItemAnimator(new DefaultItemAnimator());//设置动画效果

        fanhui.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }

    @Override
    void initData() {
        userModel = new UserModel();
        userModel.getAllCommentsByUser(getUser_id(),this);
    }

    @Override
    public void onSuccess(List<CommentsBean> object, int flag) {
        adapter = new PingjiaAdapter(MypingjiaActivity.this,object,R.layout.pingjia_item);
        recyclerView.setAdapter(adapter);
    }

    @Override
    public void onFalure() {
        showToast("网络错误");
    }
}
